<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////
//  这个文件是 JCAT PHP框架的一部，该项目和此文件 均遵循 GNU 自由软件协议
// 
//  Copyleft 2008 JeCat.cn(http://team.JeCat.cn)
//
//
//  JCAT PHP框架 的正式全名是：Jellicle Cat PHP Framework。
//  “Jellicle Cat”出自 Andrew Lloyd Webber的音乐剧《猫》（《Prologue:Jellicle Songs for Jellicle Cats》）。
//  JCAT 是一个开源项目，它像音乐剧中的猫一样自由，你可以毫无顾忌地使用JCAT PHP框架。JCAT 由中国团队开发维护。
//  正在使用的这个版本是：0.5.0 / SVN信息: $Id: class.JCAT_Message.php 1594 2009-03-31 11:29:38Z alee $
//
//
//
//  相关的链接：
//    [主页] http://jcat.JeCat.cn
//    [下载(HTTP)] http://code.google.com/p/jcat-php/downloads/list
//    [下载(svn)] svn checkout http://jcat-php.googlecode.com/svn/branches/0.4.0/Framework/ JCAT0.4
//    [在线文档] http://jcat.JeCat.cn/document
//    [社区] http://jj.jecat.cn/forum-7-1.html
//  不很相关：
//    [MP3] http://www.google.com/search?q=jellicle+songs+for+jellicle+cats+Andrew+Lloyd+Webber
//    [VCD/DVD] http://www.google.com/search?q=CAT+Andrew+Lloyd+Webber+video
//
///////////////////////////////////////////////////////////////////////////////////////////////////////
/*-- Project Introduce --*/
namespace JCAT ;




/**
 * What's this Class ?
 *
 * @author		alee
 * @access		public
 */
class Message
{


	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @param	$sMsg	string	What's this Parameter ?
	 * @param	$sType	string	What's this Parameter ?
	 * @param	$nImportance=3	int	What's this Parameter ?
	 * @return	void
	 */
	public function Message( $sMsg, $sType, $nImportance=3, $sFromClass=null, $sFromFunction=null, $bDispatchAtOnce=true ) 
	{
		ASSERT::ASSERT_STRING($sMsg) ;
		ASSERT::ASSERT_STRING($sType) ;
		ASSERT::ASSERT_INT($nImportance) ;
		ASSERT::ASSERT_ISTHESE($sFromClass,array('string','null')) ;
		ASSERT::ASSERT_ISTHESE($sFromFunction,array('string','null')) ;
	
		$this->nCreateTime		 = time() ;
		$this->nImportanceLevel	 = $nImportance ;
		$this->sType			 = $sType ;
		$this->sMessage			 = $sMsg ;

		
		if( !$sFromClass or !$sFromFunction )
		{
						$aCaller = Backtrace::GetCaller() ;
			
			$this->sFromClass = $sFromClass? $sFromClass: $aCaller->GetClass() ;
			$this->sFromFunction = $sFromFunction? $sFromFunction: $aCaller->GetFunction() ;
		}
		
		else
		{
			$this->sFromClass = $sFromClass ;
			$this->sFromFunction = $sFromFunction ;
		}
		
		
		if($bDispatchAtOnce)
		{
						MessageDispatcher::PutInMessage($this) ;
		}
	}



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetMessage() 
	{ return $this->sMessage ; }



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetType(  ) 
	{ return $this->sType ; }



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetFrom(  ) 
	{
		return $this->GetFromClass().'::'.$this->GetFromFunction() ;
	}



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetFromClass(  ) 
	{
		return $this->sFromClass? $this->sFromClass: 'Global' ;
	}



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	string
	 */
	public function GetFromFunction(  ) 
	{
		return $this->sFromFunction? $this->sFromFunction: 'Global' ;
	}



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	int
	 */
	public function GetCreateTime( $sFormat=null ) 
	{
		ASSERT::ASSERT_ISTHESE($sFormat,array('string','null')) ;
		
		if( $sFormat )
			return date($sFormat,$this->nCreateTime) ;
		else
			return $this->nCreateTime ;
	}



	/**
	 * What's this Method ?
	 * 
	 * @access	public
	 * @return	int
	 */
	public function GetImportanceLevel(  ) 
	{
		return $this->nImportanceLevel ;
	}




	// 属性 ///////////////////////////////////////////////////////////////////////////////

	/**
	 * What's this Attribute ?
	 * 
	 * @access	private
	 * @var		int
	 */
	private $nCreateTime ;

	/**
	 * What's this Attribute ?
	 * 
	 * @access	private
	 * @var		int
	 */
	private $nImportanceLevel ;

	/**
	 * What's this Attribute ?
	 * 
	 * @access	private
	 * @var		string
	 */
	private $sMessage ;

	/**
	 * What's this Attribute ?
	 * 
	 * @access	private
	 * @var		string
	 */
	private $sType ;

	/**
	 * What's this Attribute ?
	 * 
	 * @access	private
	 * @var		string
	 */
	private $sFromClass ;

	/**
	 * What's this Attribute ?
	 * 
	 * @access	private
	 * @var		string
	 */
	private $sFromFunction ;


}
?>